﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Vita.Entities; 

namespace Vita.Modules.BackgroundTasks {

  public enum TaskRunStatus {
    Started, //record created, but the process is not started yet
    Running,
    Completed,
    Canceled,
    Error,
  }

  public enum TaskRunMode {
    Sync,
    Background,
  }

  public enum InvocationType {
    Expression,
    JavaScript,
    Other,
  }

  [Entity]
  public interface ITaskInvocation {
    [PrimaryKey, Auto]
    Guid Id { get; }
    [Size(Sizes.Name)]
    string Name { get; set; }
    [Nullable, Size(Sizes.Description)]
    string Description { get; set; }
    [Nullable, Unlimited]
    string Expression { get; set; }
    [Size(Sizes.LongName)]
    string ClassName { get; set; }
    [Size(Sizes.LongName)]
    string MethodName { get; set; }
    [Nullable, Unlimited]
    string Parameters { get; set; } //json serialized parameters
  }

  [Entity]
  public interface IBackgroundTaskRun {
    [PrimaryKey, Auto]
    Guid Id { get; }

    [Size(Sizes.Name)]
    string Name { get; set; }
    [Size(Sizes.Description)]
    string Description { get; set; }
    [Nullable]
    ITaskInvocation Invocation { get; set; }

    [Auto(AutoType.CreatedOn)]
    DateTime CreatedOn { get; }
    [Auto(AutoType.UpdatedOn)]
    DateTime UpdatedOn { get; set; }
    DateTime? EndedOn { get; set; }
    int DurationMs { get; set; }

    TaskRunStatus Status { get; set; }

    [Unlimited]
    string CompletionData { get; set; }

    int Progress { get; set; }
    [Size(100), Nullable]
    string ProgressMessage { get; set; }
    [Unlimited, Nullable]
    string EndNotes { get; set; }

    [Unlimited, Nullable]
    string Errors { get; set; }

    int ErrorCount { get; set; }
  }



}
